<?php


namespace app\index\model;


use think\Db;
use think\Model;

class Userstatus extends Model
{

    /**
     * 获取用户基本信息，用户情况
     * ywh开发
     *
     * @param $phone
     * @return Userstatus[]|\think\Collection
     */
    public function getUserState($phone){
        return $this->alias('state')
            ->join(['user' => 'user'],'user.user_id = state.user_id')
            ->join(['project' => 'project'],'project.user_id = user.user_id')
            ->join(['experience' => 'temp'],'user.user_id = temp.user_id')
            ->join(['study' => 'study'],'study.user_id = user.user_id')
            ->join(['certificate' => 'certificate'],'study.user_id = certificate.user_id')
            ->field(['user.header','user.username','user.sex','user.birthday','user.email','user.phone','user.workplace','user.identity'])
            ->field('(UNIX_TIMESTAMP(NOW()) - birthday) / 31536000 as age')
            ->field(['state.status','state.ability','state.advantage','state.exp_jobtype','state.exp_job','state.exp_moeny','state.exp_nature'])
            ->field(['temp.company_name','temp.com_class','temp.department','temp.job','temp.injob_time','temp.outjob_time','(temp.outjob_time - temp.injob_time) / 31536000 as year'])
            ->field(['project.project','project.pro_name','project.mypro'] )
            ->field(['study.school','study.level','study.subject','study.school_time','study.out_school','study.in_school'])
            ->field(['certificate.certificate','certificate.mechanism','certificate.grade','certificate.is_check'])
            ->where('user.phone','=',$phone)
            ->select();
    }

    /**
     * 个人页修改用户个人情况
     * ywh开发
     *
     * @param $human
     * @param $data
     * @return Userstatus
     */
    public function editState($human,$data){
        return $this->alias('state')
            ->where('user_id','=',$human)
            ->update($data);
    }

    /**
     * 获取该表的ID
     * @param $human
     * @return Userstatus
     */
    public function getStateId($human){
        return $this->where('user_id','=',$human)->field('userstatus_id')->find();
    }
}